﻿using GrainManage.Server.Business;
using GrainManage.Server.Models;
using GrainManage.Server.Util;
using System;
using System.Text.RegularExpressions;
using System.Web.Mvc;

namespace GrainManage.Server.Controllers
{
    public class ApiDetailController : BaseController
    {
        public ActionResult GetInfo(string controllerName = "Account", string type = "")
        {
            if (ApiGenerator.ControllerType.ContainsKey(controllerName ?? string.Empty))
            {
                ControllerModel result = null;
                if (Regex.IsMatch(type ?? string.Empty, ".*schema+", RegexOptions.IgnoreCase))
                {
                    result = GrainManage.Server.Util.ApiGenerator.GetApiInfo(controllerName, true, false);
                }
                else
                {
                    result = GrainManage.Server.Util.ApiGenerator.GetApiInfo(controllerName, false, false);
                }

                return View("Index", result);
            }
            return Content("Sorry,the Controller does not exist.");
        }
    }
}
